<?php

use App\Models\User;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserInfoTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_info', function (Blueprint $table) {

            $table->increments('id')->comment('用户ID');

            $table->enum('gender', [
                User::GENDER_MALA,
                User::GENDER_FEMALE
            ])->nullable()->comment('性别');

            $table->date('birthday')->nullable()->comment('生日');

            $table->ipAddress('register_ip')->nullable()->comment('注册时的IP地址');
            $table->string('realname',20)->nullable()->comment('真实姓名');

            // 删除用户时, 自动删除用户信息
            $table->foreign('id')
                ->references('id')->on('users')
                ->onDelete('cascade');

            $table->comment = '用户信息表';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_info');
    }
}